package com.kuang.controller;

import com.kuang.service.ExcelService;
import com.kuang.util.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/teacher")
public class ExcelController {

    private ExcelService excelService;
    // 标准写法
    @Autowired
    public void setExcelService(ExcelService excelService) {
        this.excelService = excelService;
    }

    /**
     * 导入excel表中信息
     */
    @PostMapping("/excel")
    public ResultModel<String> teacherExcel(MultipartFile file) throws Exception {
        String filename = file.getOriginalFilename();
        if (filename.indexOf("教师") != -1){
            // 教师表
            excelService.teacherExcel(file);
        }else {
            // 学生表
            excelService.studentExcel(file);
        }
        return ResultModel.success("上传成功");
    }

}
